package com.example.serviceproduct.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.system.SystemBlockException;
import com.example.serviceproduct.service.ProductService;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {
    @Override
//    @SentinelResource
    @SentinelResource(value = "testReturnStringxxx",blockHandler = "testFallback")
//    @SentinelResource(value = "testReturnStringxxx",fallback = "testFallback")
    public String testReturnString() throws SystemBlockException {
        if(1==1){
//            throw new SystemBlockException("testReturnString", "testReturnString");
            int i=1/0;
        }
        return "执行成功！";
    }

    // testFallback的声明和使用这个兜底回调的方法一样，你可以可选地追加一个BlockException
//    public String testFallback(BlockException ex){
    public String testFallback(Throwable ex){

        return "执行blockHandler的兜底回调！";
    }
}
